<?php
/**
 * 系統名稱: Lotto 系統
 * 檔案說明: 專案管理-修改
 * $Author$
 * $Id$
 *
 */

$isSpecial = (int)$_data["isSpecial"];
$intSpecialNumType = (int)$_data["SpecialNumType"];
$isRealShow = (int)$_data["isRealShow"];
$intGambleID = (int)$_data["GambleID"];
if(strlen($isSpecial) == 0)$isSpecial = 0;
if(strlen($isRealShow) != 1)$isRealShow = 0;
$strBT = trim($_data["Bet_Type"]);
$arrBType = split(",", $strBT);
$arrOtherMsg = split(",", trim($_data["OtherMsg"]));
$strLottoNumber = trim($_data["strLottoNumber"]);

$arrSumStake = array();
$arrSumPayOff = array();
$arrSumCommission = array();

$strSQL = "select * from `bet_TodayGame".$intLID."` where LottoID = ".$intLID." and GambleID = '".$intGambleID."' and Bet_Type in (".$strBT.") ";
if($strBT == "92" || $strBT == "93"){
	$intBT = (int)$strBT;
	$strRealTip = ($isRealShow == 0)?"":"Real";

	//找出三定位 1000 個號碼的總注單量
	$strSumSQL = "select SUM(tolWager + tolSuppleWager) as tolWager, SUM(tol".$strRealTip."Stake - tolSuppleStake) as tolStake, SUM(tol".$strRealTip."PayOff - tolSupplePayOff) as tolPayOff, SUM(tolCommission - tolSuppleCommission) as tolCommission from `bet_TodayGame".$intLID."` where LottoID = ".$intLID." and GambleID = '".$intGambleID."' and Bet_Type = ".$strBT;
	if(!$RS = PMA_mysql_query($strSumSQL, $$_Conn)){
		$GLOBALS["errormessage"] = "Find TodayGame Data Error!!";
		$GLOBALS["errorhidden"] = "Error: ".PMA_mysql_error($$_Conn)."\nSQL:".$strSQL."\nLine:".__LINE__."\nPage:".__FILE__;
		ErrMsgOutputHTML("Error", "", 1);
	}
	$Rows = PMA_mysql_fetch_object($RS);
	$arrSumStake[$intBT] = $Rows -> tolStake;
	$arrSumPayOff[$intBT] = $Rows -> tolPayOff;
	$arrSumCommission[$intBT] = $Rows -> tolCommission;

	switch($arrOtherMsg[0]){
		case "Sort": //排序
			$strSQL = "select *, (".($Rows -> tolStake - $Rows -> tolCommission)." - tol".$strRealTip."Stake - tol".$strRealTip."PayOff + tolSuppleStake + tolSupplePayOff) as preWin from `bet_TodayGame".$intLID."` where LottoID = ".$intLID." and GambleID = '".$intGambleID."' and Bet_Type = ".$intBT." order by preWin, Number limit ";
			$strSQL .= ($strBT != "93")?"100":"220";
			break;

		default:
			if($strBT == "93"){
				$strSQL .= " order by Number";
			}else{
				$strSQL .= "and Number in (".$strLottoNumber.") order by Number";
			}
			break;
	}
}else{
	$strSQL .= "order by Bet_Type";
}
//print "<!--".$strSQL."//-->";

if(!$RS = PMA_mysql_query($strSQL, $$_Conn)){
	$GLOBALS["errormessage"] = "Find TodayGame Data Error!!";
	$GLOBALS["errorhidden"] = "Error: ".PMA_mysql_error($$_Conn)."\nSQL:".$strSQL."\nLine:".__LINE__."\nPage:".__FILE__;
	ErrMsgOutputHTML("Error", "", 1);
}

if(PMA_mysql_num_rows($RS) == 0){
	$GLOBALS["errormessage"] = "No TodayGame Data!!";
	ErrMsgOutputHTML("Error", "", 1);
}
	
$intNum = -1;
while($Rows = PMA_mysql_fetch_object($RS)){
	if($isRealShow == 0){
		$tolStake = $Rows -> tolStake;
		$tolPayOff = $Rows -> tolPayOff;
		$tolWager = $Rows -> tolWager;
		$tolCommission = 0;
	}else{
		$tolStake = $Rows -> tolRealStake;
		$tolPayOff = $Rows -> tolRealPayOff;
		$tolWager = $Rows -> tolWager;
		$tolCommission = $Rows -> tolCommission;
	}
	if(empty($tolStake))$tolStake = 0;
	if(empty($tolPayOff))$tolPayOff = 0;
	if(empty($tolCommission))$tolCommission = 0;
	if(empty($tolWager))$tolWager = 0;
	$tolStake -= $Rows -> tolSuppleStake;
	$tolPayOff -= $Rows -> tolSupplePayOff;
	$tolCommission -= $Rows -> tolSuppleCommission;
	$intBT = $Rows -> Bet_Type;
	$intApointNum = $_arrGLineNumToApointNum[$Rows -> LottoID][$Rows -> Bet_Type][$Rows -> Number];
	if($intApointNum == null)$intApointNum = 0;
	$intNum = ($intBT == 92 || $intBT == 93)?($intNum+1):$Rows -> Number;

	$strCon .= "parent.Game".$intBT."[".$intNum."]=new Array('".$Rows -> LottoID."','".$Rows -> GambleID."','".$intBT."','".$Rows -> Number."','".$Rows -> OddsID."','".round(($Rows -> Odds + $_arrGambleType[$Rows -> Bet_Type][$intApointNum]), 3)."','".$Rows -> isStopBet."','".$tolWager."','".$tolStake."','".$tolPayOff."','".$tolCommission."');\n";

	switch($Rows -> Bet_Type){
		case 92:
		case 93:
			break;

		default:
			$arrSumStake[$Rows -> Bet_Type] += $tolStake;
			$arrSumPayOff[$Rows -> Bet_Type] += $tolPayOff;
			$arrSumCommission[$Rows -> Bet_Type] += $tolCommission;
			//$arrSumWStake[$Rows -> Bet_Type] += $tolStake + $Rows -> tolSuppleStake;
			break;
	}
}


/*=================================================================*/
header("Cache-Control: no-store, no-cache, must-revalidate");	  // HTTP/1.1
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");															  // HTTP/1.0
?><meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script language="JavaScript">
<!--
<?php 
print $strCon."\n";
print "parent.isEmergency = ".((empty($_isStopAllBet))?"0":$_isStopAllBet).";\n";
print "parent.changEmergency();\n";

foreach($arrSumStake as $intBT => $val){
	print "parent.sumStake[".$intBT."] = ".round($arrSumStake[$intBT]).";\n";
	print "parent.sumPayOff[".$intBT."] = ".round($arrSumPayOff[$intBT]).";\n";
	print "parent.sumCommission[".$intBT."] = ".round($arrSumCommission[$intBT]).";\n";
	//print "parent.sumWStake[".$intBT."] = ".round($arrSumWStake[$intBT]).";\n";
}
switch($strBT){
	case "51";
	case "52";
	case "53";
	case "54";
	case "55";
	case "56";
	case "57";
	case "58";
	case "59";
	case "60";
	case "61";
	case "62";
	case "63";
	case "84";
	case "85";
	case "86";
	case "51,52,53,54,55,56,57,58,59,60,61,62,63,84,85,86":
		print "parent.ShowNumberOdds51(51);\n";
		break;

	//雙飛
	case "64";
	case "65";
	case "66";
	case "67";
	case "64,65,66";
		print "parent.ShowTwinNumer(".$strBT.");\n";
		break;

	case "68";
	case "69";
	case "70";
	case "71";
	case "72";
	case "68,69,70,71,72":
		print "parent.ShowAssembleNumber(68);\n";
		break;

	case "73";
	case "74";
	case "75";
	case "76";
	case "77";
	case "73,74,75,76,77":
		print "parent.ShowAssembleNumber(73);\n";
		break;

	case "78";
	case "79";
	case "80";
	case "81";
	case "82";
	case "83";
	case "78,79,80,81,82,83":
		print "parent.ShowRowsNumber(78);\n";
		break;

	case "87";
	case "88";
	case "89";
	case "90";
	case "91";
	case "87,88,89,90,91":
		print "parent.ShowOPNumber(87);\n";
		break;

	case "92";
		print "parent.ShowTrinityNumber(92);\n";
		break;

	case "93":
		print "parent.Show3WordNumber(93);\n";
		break;
}
?>
//-->
</script>